package com.cloudOffice.controller;


import com.cloudOffice.model.wechat.Menu;
import com.cloudOffice.result.Result;
import com.cloudOffice.service.MenuService;
import com.cloudOffice.vo.wechat.MenuVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单
 */
@Slf4j
@Tag(name = "wechat管理")
@RestController("MenuController")
@RequestMapping("/admin/wechat/menu")
public class MenuController {
	
	@Resource
	private MenuService menuService;
	
	/**
	 * 根据id获取菜单
	 */
	@Operation(summary = "根据id获取菜单")
	@GetMapping("/get/{id}")
	public Result<Menu> get(@PathVariable Long id) {
		log.info("根据id获取菜单：id: {}", id);
		return Result.success(menuService.getById(id));
	}
	
	/**
	 * 添加菜单
	 */
	@Operation(summary = "添加菜单")
	@PostMapping("/save")
	public Result<?> save(@RequestBody Menu menu) {
		log.info("添加菜单：menu: {}", menu);
		menuService.save(menu);
		return Result.success();
	}
	
	
	/**
	 * 修改菜单
	 */
	@PutMapping("/update")
	@Operation(summary = "修改菜单")
	public Result updateById(@RequestBody Menu menu) {
		log.info("修改菜单：menu: {}", menu);
		menuService.updateById(menu);
		return Result.success();
	}
	
	/**
	 * 根据id删除菜单
	 */
	@Operation(summary = "根据id删除菜单")
	@DeleteMapping("remove/{id}")
	public Result<?> remove(@PathVariable Long id) {
		log.info("根据id删除菜单：id: {}", id);
		menuService.removeById(id);
		return Result.success();
	}
	
	
	/**
	 * 删除全部菜单
	 */
	@Operation(summary = "删除全部菜单")
	@DeleteMapping("/removeMenu")
	public Result<?> removeMenu() {
		log.info("删除全部菜单");
		menuService.removeMenu();
		return Result.success();
	}
	
	
	/**
	 * 同步菜单
	 */
	@GetMapping("/syncMenu")
	@Operation(summary = "同步菜单")
	public Result<?> createMenu() {
		log.info("同步菜单");
		menuService.syncMenu();
		return Result.success();
	}
	
	/**
	 * 获取全部菜单
	 */
	@GetMapping("/findMenuInfo")
	@Operation(summary = "获取全部菜单")
	public Result<List<MenuVo>> findMenuInfo() {
		log.info("获取全部菜单");
		return Result.success(menuService.findMenuInfo());
	}
	
}

